package com.ruoyi.web.controller.answer;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.answer.domain.QtAnswer;
import com.ruoyi.answer.service.IQtAnswerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 答疑Controller
 * 
 * @author zqq
 * @date 2021-11-19
 */
@RestController
@RequestMapping("/answer/answer")
public class QtAnswerController extends BaseController
{
    @Autowired
    private IQtAnswerService qtAnswerService;

    /**
     * 查询答疑列表
     */
    @PreAuthorize("@ss.hasPermi('answer:answer:list')")
    @GetMapping("/list")
    public TableDataInfo list(QtAnswer qtAnswer)
    {
        startPage();
        List<QtAnswer> list = qtAnswerService.selectQtAnswerList(qtAnswer);
        return getDataTable(list);
    }

    /**
     * 导出答疑列表
     */
    @PreAuthorize("@ss.hasPermi('answer:answer:export')")
    @Log(title = "答疑", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QtAnswer qtAnswer)
    {
        List<QtAnswer> list = qtAnswerService.selectQtAnswerList(qtAnswer);
        ExcelUtil<QtAnswer> util = new ExcelUtil<QtAnswer>(QtAnswer.class);
        return util.exportExcel(list, "答疑数据");
    }

    /**
     * 获取答疑详细信息
     */
    @PreAuthorize("@ss.hasPermi('answer:answer:query')")
    @GetMapping(value = "/{answerId}")
    public AjaxResult getInfo(@PathVariable("answerId") String answerId)
    {
        return AjaxResult.success(qtAnswerService.selectQtAnswerByAnswerId(answerId));
    }

    /**
     * 新增答疑
     */
    @PreAuthorize("@ss.hasPermi('answer:answer:add')")
    @Log(title = "答疑", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QtAnswer qtAnswer)
    {
        return toAjax(qtAnswerService.insertQtAnswer(qtAnswer));
    }

    /**
     * 修改答疑
     */
    @PreAuthorize("@ss.hasPermi('answer:answer:edit')")
    @Log(title = "答疑", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QtAnswer qtAnswer)
    {
        LoginUser loginUser=getLoginUser();;
        qtAnswer.setAnswerInt(loginUser.getUserId());
        return toAjax(qtAnswerService.updateQtAnswer(qtAnswer));
    }

    /**
     * 删除答疑
     */
    @PreAuthorize("@ss.hasPermi('answer:answer:remove')")
    @Log(title = "答疑", businessType = BusinessType.DELETE)
	@DeleteMapping("/{answerIds}")
    public AjaxResult remove(@PathVariable String[] answerIds)
    {
        return toAjax(qtAnswerService.deleteQtAnswerByAnswerIds(answerIds));
    }
}
